using System.Collections;
using UnityEngine;

public static class YieldHelper
{
    public static WaitForEndOfFrame WaitForEndOfFrame = new ();

    /// <summary>
    /// 等待指定时间
    /// </summary>
    /// <param name="totalTime"></param>
    /// <param name="ignoreTimeScale"></param>
    /// <returns></returns>
    public static IEnumerator WaitForSeconds(float totalTime, bool ignoreTimeScale = false)
    {
        float time = 0;
        while (time < totalTime)
        {
            time += (ignoreTimeScale ? Time.unscaledDeltaTime : Time.deltaTime);
            yield return null;
        }
    }

    /// <summary>
    /// 等待指定帧数
    /// </summary>
    /// <param name="i"></param>
    /// <returns></returns>
    public static IEnumerator WaitForFrame(int i)
    {
        int count = 0;
        while (count < i)
        {
            yield return null;
            count++;
        }
    }
}